package com.gouaixin.bee.beeframework2.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ab.util.AbImageUtil;
import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.bean.ZhenxinhuaFriend;
import com.gouaixin.bee.beeframework2.tool.PreferencesUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：Fisher on 2015/5/11 09:33
 * 邮箱：630709658@qq.com
 * 座右铭:知识来自积累,经验源于总结
 */
public class B2_fensiAdapter extends BaseAdapter {
    Context context;
    List<ZhenxinhuaFriend> datas=new ArrayList<ZhenxinhuaFriend>();

    public B2_fensiAdapter(Context context) {
        this.context = context;
    }

    public void setData(List<ZhenxinhuaFriend> datas) {
        this.datas=datas;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.item_guanzhu,null);


        final ImageView icon= (ImageView) convertView.findViewById(R.id.icon);
        TextView name= (TextView) convertView.findViewById(R.id.name);
        TextView address= (TextView) convertView.findViewById(R.id.address);


        final ZhenxinhuaFriend bean=datas.get(position);


        ImageLoader imageLoader=ImageLoader.getInstance();
        imageLoader.loadImage(bean.getJicon(),new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {

            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {

            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {
//                imageLoader.displayImage(com.ytr.mymodule.app.bean.getIcon(),icon);
                icon.setBackgroundDrawable(AbImageUtil.bitmapToDrawable(bitmap));
            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });



        name.setText(bean.getJname());

        String addressStr= PreferencesUtils.getString(context, "address");
        address.setText(addressStr);


        return convertView;
    }
}
